import javax.swing.JOptionPane;
import javax.swing.JPanel;
/**
 * 
 *is the control class of Book ManagementControl Gui.
 */
public class BookManagementControl
{		
	/** Local Controler for Add Subject*/
	public AddSubjectControl AddSubjectCTRL;
	/** Local Controler for Add Field*/
	public AddFieldControl AddFieldCTRL;
	/**
	 * this method switches from book managment gui to Add subject Gui
	 */
	public void o_addSubject(JPanel BookMngpanel) 
	{		
		BookMngpanel.setEnabled(false);
		BookMngpanel.setVisible(false);
		AddSubjectCTRL = new AddSubjectControl();
		AddSubjectGui AddSubjectGui = new AddSubjectGui();
		BookMngpanel.setEnabled(false);
		BookMngpanel.setVisible(false);
		Main.log.frame.setSize(550,515);
		Main.log.frame.add(AddSubjectGui.panel);
		AddSubjectGui.panel.setEnabled(true);
		AddSubjectGui.panel.setVisible(true);
	}
	
	/**
	 * this method switches from book managment gui to Add Field Gui
	 */
	public void o_addField(JPanel BookMngpanel) 
	{		
		BookMngpanel.setEnabled(false);
		BookMngpanel.setVisible(false);
		AddFieldCTRL = new AddFieldControl();
		AddFieldGui AddField_Gui = new AddFieldGui();
		BookMngpanel.setEnabled(false);
		BookMngpanel.setVisible(false);
		Main.log.frame.setSize(550,515);
		Main.log.frame.add(AddField_Gui.panel);
		AddField_Gui.panel.setEnabled(true);
		AddField_Gui.panel.setVisible(true);
	}
	/**
	 * this method Goes back to the last Gui Screen - Main menu
	 */	
	public void o_cancel()
	{
		Main.bookManagement.panel.setVisible(false);
		Main.bookManagement.panel.setEnabled(false);
		if(Main.gusers.authorozations==1) Main.log.frame.setSize(450,320);
		else if(Main.gusers.authorozations==2) Main.log.frame.setSize(450,400);
		else if(Main.gusers.authorozations==3) Main.log.frame.setSize(450,515);
		Main.welcomeScreen.panel.setVisible(true);
		Main.welcomeScreen.panel.setEnabled(true);
	}

	/**
	 * this method logs out of the system
	 */	
	public void o_logout(JPanel BookMngpanel)
	{
		if(JOptionPane.showConfirmDialog(null, "Are you sure? \"Yes/No\" message dialog box.","Confirmation" ,JOptionPane.OK_CANCEL_OPTION) == 0)
		{
			BookMngpanel.setEnabled(false);
			BookMngpanel.setVisible(false);
			Main.log.loginData = new String[3];
			Main.log.loginData[0]=Main.gusers.id;
			Main.log.loginData[1]="logout";
			Main.log.loginData[2]=Main.gusers.id;		
			Main.log.connection= new ClientQuery(Main.serverIP,5555);
			Main.log.connection.accept("logout");
			Main.log.user.setText("");
			Main.log.pass.setText("");
			Main.log.frame.setSize(650,550);
			Main.log.panel.setEnabled(true);
			Main.log.panel.setVisible(true);
		}
	}


		
}
